﻿Imports System.Data.OleDb

Public Class addroute
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_addaroute_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_addaroute.Click

        'add random file names to picture upload
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".png"

        If fu_routepicture.HasFile Then
            Dim picLocationOnServerHardDisk = Request.MapPath("routepics") & "/" & newFileName
            fu_routepicture.SaveAs(picLocationOnServerHardDisk)
        End If

 'add random file names to route details file upload

        Dim myGuidFile As New System.Guid
        myGuidFile = Guid.NewGuid()
        Dim newDetailsFile = myGuidFile.ToString() + ".doc"

        If fu_routepicture.HasFile Then
            Dim fiLocationOnServerHardDisk = Request.MapPath("routedetails") & "/" & newDetailsFile
            fu_routepicture.SaveAs(fiLocationOnServerHardDisk)
        End If

        'submit route btn click code
        Dim OleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("walkingweb").ConnectionString)
        Dim SqlString As String = "Insert into routes (RouteName,CityTown,County,Country,Description,Distance,Picture,DetailsFile,DateAdded,Visitor) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9,@f10)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, OleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_routename.Text)
        cmd.Parameters.AddWithValue("@f2", tb_routecitytown.Text)
        cmd.Parameters.AddWithValue("@f3", tb_routecounty.Text)
        cmd.Parameters.AddWithValue("@f4", tb_routecountry.Text)
        cmd.Parameters.AddWithValue("@f5", tb_routedescription.Text)
        cmd.Parameters.AddWithValue("@f5", tb_routedistance.Text)
        cmd.Parameters.AddWithValue("@f7", "routepics/" & newFileName)
        cmd.Parameters.AddWithValue("@f8", "routedetails/" & newDetailsFile)
        cmd.Parameters.AddWithValue("@f9", Date.Today)
        cmd.Parameters.AddWithValue("@f10", User.Identity.Name)
        OleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("addrouteconfirm.aspx")

    End Sub
End Class